#pragma once
#include <iostream>
#include <spdlog/spdlog.h>
#include <spdlog/async.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h> 
#include <string>

std::shared_ptr<spdlog::logger> g_default_logger;
void init_logger(bool mode, const std::string& file, int level)
{
    if(mode == false)
    {
        g_default_logger = spdlog::stdout_color_mt("default-logger");
        g_default_logger->flush_on((spdlog::level::level_enum) level);
        g_default_logger->set_level((spdlog::level::level_enum) level);
    }
    else
    {
        g_default_logger = spdlog::basic_logger_mt("default-logger", file);
        g_default_logger->flush_on((spdlog::level::level_enum) level);
        g_default_logger->set_level((spdlog::level::level_enum) level);
    }
    g_default_logger->set_pattern("[%n][%H:%M:%S][%t][%-8l]%v");
}

#define LOG_TRACE(forms, ...) g_default_logger->trace(std::string("[{}:{}] ") + forms, __FILE__, __LINE__, ##__VA_ARGS__)
#define LOG_DEBUG(forms, ...) g_default_logger->debug(std::string("[{}:{}] ") + forms, __FILE__, __LINE__, ##__VA_ARGS__)
#define LOG_INFO(forms, ...) g_default_logger->info(std::string("[{}:{}] ") + forms, __FILE__, __LINE__, ##__VA_ARGS__)
#define LOG_WARN(forms, ...) g_default_logger->warn(std::string("[{}:{}] ") + forms, __FILE__, __LINE__, ##__VA_ARGS__)
#define LOG_ERROR(forms, ...) g_default_logger->error(std::string("[{}:{}] ") + forms, __FILE__, __LINE__, ##__VA_ARGS__)
#define LOG_FATAL(forms, ...) g_default_logger->critical(std::string("[{}:{}] ") + forms, __FILE__, __LINE__, ##__VA_ARGS__)